<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kafka 压缩机制深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #2d3748;
            color: #e2e8f0;
            padding: 4px 8px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            font-size: 14px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 12px;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
                <h1 class="text-5xl font-bold mb-6">Kafka 压缩机制深度解析</h1>
                <p class="text-xl opacity-90 leading-relaxed">
                    探索 Apache Kafka 如何通过智能压缩技术优化存储空间、提升网络传输效率，为大数据处理提供强大支撑
                </p>
                <div class="mt-8 flex justify-center space-x-8">
                    <div class="text-center">
                        <i class="fas fa-compress text-3xl mb-2"></i>
                        <p class="text-sm">高效压缩</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-rocket text-3xl mb-2"></i>
                        <p class="text-sm">性能优化</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-database text-3xl mb-2"></i>
                        <p class="text-sm">存储节省</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="max-w-4xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <p class="text-lg leading-relaxed text-gray-700 indent-8">
                    Kafka的压缩机制是一个重要的功能，旨在优化存储空间和提高网络传输效率。通过压缩消息，Kafka可以减少存储成本和提高系统的整体性能。
                </p>
            </div>
        </div>

        <!-- Compression Algorithms Visualization -->
        <div class="max-w-6xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <h2 class="text-3xl font-bold mb-8 text-center text-gradient">压缩算法对比分析</h2>
                <div class="mermaid">
                    graph TD
                        A[Kafka 压缩算法] --> B[Gzip]
                        A --> C[Snappy]
                        A --> D[LZ4]
                        A --> E[Zstd]
                        
                        B --> B1[高压缩率<br/>CPU开销大]
                        C --> C1[快速压缩<br/>实时处理]
                        D --> D1[高吞吐量<br/>低延迟]
                        E --> E1[平衡性能<br/>新型算法]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#f59e0b,stroke:#fff,stroke-width:2px,color:#fff
                        style C fill:#10b981,stroke:#fff,stroke-width:2px,color:#fff
                        style D fill:#3b82f6,stroke:#fff,stroke-width:2px,color:#fff
                        style E fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </div>

        <!-- Basic Concepts -->
        <section class="max-w-4xl mx-auto mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">压缩的基本概念</h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-bullseye"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">压缩目的</h3>
                    <p class="text-gray-700 leading-relaxed">
                        在消息传输和存储过程中，压缩能够显著降低数据大小，减少带宽使用，提高数据传输速度，从而提升系统的吞吐量。
                    </p>
                </div>
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-layer-group"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">支持的压缩格式</h3>
                    <div class="space-y-2">
                        <div class="flex items-center">
                            <span class="code-block mr-2">Gzip</span>
                            <span class="text-sm text-gray-600">高压缩率，CPU开销大</span>
                        </div>
                        <div class="flex items-center">
                            <span class="code-block mr-2">Snappy</span>
                            <span class="text-sm text-gray-600">快速压缩，实时处理</span>
                        </div>
                        <div class="flex items-center">
                            <span class="code-block mr-2">LZ4</span>
                            <span class="text-sm text-gray-600">高吞吐量应用</span>
                        </div>
                        <div class="flex items-center">
                            <span class="code-block mr-2">Zstd</span>
                            <span class="text-sm text-gray-600">高压缩率与速度结合</span>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Working Principle -->
        <section class="max-w-4xl mx-auto mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">压缩的工作原理</h2>
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <div class="space-y-6">
                    <div class="border-l-4 border-purple-500 pl-6">
                        <h3 class="text-xl font-bold mb-2 flex items-center">
                            <i class="fas fa-compress-arrows-alt mr-3 text-purple-500"></i>
                            消息压缩
                        </h3>
                        <p class="text-gray-700 leading-relaxed">
                            在生产者发送消息时，可以选择启用压缩。生产者将消息发送到Kafka主题时，Kafka会对同一批消息进行压缩。压缩的策略可以通过配置参数
                            <span class="code-block">compression.type</span>来指定。
                        </p>
                    </div>
                    
                    <div class="border-l-4 border-blue-500 pl-6">
                        <h3 class="text-xl font-bold mb-2 flex items-center">
                            <i class="fas fa-boxes mr-3 text-blue-500"></i>
                            批量压缩
                        </h3>
                        <p class="text-gray-700 leading-relaxed">
                            Kafka的压缩机制主要基于批量操作。生产者在发送消息时，会先将消息批量收集，并在发送前进行压缩。通过配置
                            <span class="code-block">batch.size</span>和<span class="code-block">linger.ms</span>参数，可以控制批量的大小和延迟时间，从而优化压缩效果。
                        </p>
                    </div>
                    
                    <div class="border-l-4 border-green-500 pl-6">
                        <h3 class="text-xl font-bold mb-2 flex items-center">
                            <i class="fas fa-hdd mr-3 text-green-500"></i>
                            消息存储
                        </h3>
                        <p class="text-gray-700 leading-relaxed">
                            压缩后的消息在Kafka的日志中以压缩格式存储。Kafka使用段文件（segment file）来管理消息，每个段文件包含一系列消息，经过压缩后以节省空间。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Compression Flow Diagram -->
        <section class="max-w-6xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <h2 class="text-3xl font-bold mb-8 text-center text-gradient">压缩流程图</h2>
                <div class="mermaid">
                    graph LR
                        A[生产者] -->|原始消息| B[消息批量收集]
                        B -->|批量消息| C[压缩处理]
                        C -->|压缩消息| D[网络传输]
                        D -->|压缩消息| E[Kafka Broker]
                        E -->|存储| F[段文件]
                        F -->|读取| G[消费者拉取]
                        G -->|解压缩| H[消费者]
                        
                        style A fill:#10b981,stroke:#fff,stroke-width:2px,color:#fff
                        style C fill:#f59e0b,stroke:#fff,stroke-width:2px,color:#fff
                        style E fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style H fill:#10b981,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </section>

        <!-- Decompression and Consumption -->
        <section class="max-w-4xl mx-auto mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">解压缩与消费</h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-gradient-to-br from-purple-50 to-blue-50 rounded-xl p-6 border border-purple-200">
                    <h3 class="text-xl font-bold mb-3 flex items-center">
                        <i class="fas fa-expand-arrows-alt mr-3 text-purple-600"></i>
                        消费者解压缩
                    </h3>
                    <p class="text-gray-700 leading-relaxed">
                        当消费者拉取消息时，Kafka会自动解压缩这些消息。消费者并不需要关心消息的压缩格式，Kafka会根据主题的配置进行相应的解压。
                    </p>
                </div>
                <div class="bg-gradient-to-br from-blue-50 to-green-50 rounded-xl p-6 border border-blue-200">
                    <h3 class="text-xl font-bold mb-3 flex items-center">
                        <i class="fas fa-eye-slash mr-3 text-blue-600"></i>
                        透明性
                    </h3>
                    <p class="text-gray-700 leading-relaxed">
                        压